<!--
 * @Author: guo wei
 * @LastEditors: [guo wei]
 * @LastEditTime: 2024-03-06 23:20:22
 * @Description: 
-->
<template>
  <div class="wrap">
    <div class="side-bar">
      <div class="user-info">
        <div>{{ loginName }}</div>
        <!-- <div>ID:1333333333</div> -->
      </div>
      <div class="side-bottom">
        <!-- <el-button type="primary" @click="goUpload">上传模型</el-button> -->
        <router-link to="/model">+ 上传模型</router-link>
        <div class="box-tip">目前仅支持sketchup，如需更多模型支持，点击</div>
      </div>
    </div>
    <div class="main">
      <NavBar></NavBar>
      <div class="main-content">
        <div class="main-title">最近生成</div>
        <el-row :gutter="50" style="margin-top: 20px">
          <el-col
            v-for="(item, index) in modelList"
            :key="index"
            :span="6"
            style="margin-bottom: 15px"
          >
            <el-card
              @click="goReport(item)"
              class="card-item"
              :body-style="{ padding: '0px' }"
            >
              <img
                src="https://shadow.elemecdn.com/app/element/hamburger.9cf7b091-55e9-11e9-a976-7f4d0b07eef6.png"
                class="image"
              />
              <div style="padding: 14px">
                <span>{{ item.modelInfoName }}</span>
                <div class="bottom">
                  <time class="time">最近修改</time>
                  <time class="time">{{ item.uploadTime }}</time>
                </div>
              </div>
            </el-card>
          </el-col>
        </el-row>
      </div>
    </div>
  </div>
</template>
<script setup>
import { ref, reactive, onMounted, onUnmounted } from "vue";
import NavBar from "@/layout/components/Navbar.vue";
import { getPptInfos } from "@/api/model";
import { useRouter } from "vue-router";
import Cookies from "js-cookie";
import cache from "@/plugins/cache";
const router = useRouter();
const modelList = ref([]);
const loginName = ref("");
const getList = async () => {
  try {
    const res = await getPptInfos({ count: false });
    if (res.code == 200) {
      modelList.value = res.result.list || [];
    }
  } catch (error) {}
};
getList();
onMounted(() => {
  const name = cache.local.get("loginName");
  if (name != null) {
    loginName.value = name;
  }
});
const goReport = (data) => {
  console.log("goReport", data);
  // router.push("/report");
  router.push({
    path: "/report",
    query: {
      modelId: data.modelInfoId,
      pptInfoId:data.pptInfoId
    },
  });
};
</script>
<style lang="scss" scoped>
.wrap {
  display: flex;
  background: #fbf8f8;
  height: 100%;
  .side-bar {
    width: 200px;
    background: #fff;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding-bottom: 50px;
    .user-info {
      padding: 20px;
      margin-top: 20px;
      border-bottom: 1px solid #eee;
      div {
        margin-bottom: 10px;
      }
    }
    .side-bottom {
      padding: 20px;
      .box-tip {
        font-size: 12px;
        color: #999;
        margin-top: 10px;
        padding-top: 10px;
        border-top: 1px solid #eee;
      }
    }
  }
  .main {
    flex: 1;
    .main-content {
      padding: 20px;
      height: calc(100% - 50px);
      overflow-x: hidden;
      overflow-y: auto;
      .card-item {
        // margin-bottom: 15px;
        height: 100%;
        text-align: center;
        cursor: pointer;
      }
    }
  }
}
</style>
